package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import pojo.SongList;
import service.PlayerBusiness;
import service.ServiceFactory;
import util.JsonParser;

@Controller
public class ListTransfer {

	private PlayerBusiness playerBusiness = ServiceFactory.getPlayBusiness();
	private JsonParser jsonParser = new JsonParser();

	@ResponseBody
	@RequestMapping(value = "/createSlist", method = {
			RequestMethod.POST }, produces = "application/json;charset=UTF-8")
	public String createSlist(@RequestBody String createSlistJson) {
		SongList songList = jsonParser.parseSongList(createSlistJson);
		String json = playerBusiness.createSlist(songList.getUserId(), songList.getSongListName());
		return json;
	}

	@ResponseBody
	@RequestMapping(value = "/deleteSlist/{slistId}", method = {
			RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	public String deleteSlist(@PathVariable("slistId") int slistId) {
		String json = playerBusiness.deleteSlist(slistId);
		return json;
	}

	@ResponseBody
	@RequestMapping(value = "/modifySlist", method = {
			RequestMethod.POST }, produces = "application/json;charset=UTF-8")
	public String modifySlist(@RequestBody String modifySlistJson) {
		SongList songList = jsonParser.parseSongList(modifySlistJson);
		String json = playerBusiness.modifySlist(songList.getSongListId(), songList.getSongListName(),
				songList.getDescription());
		return json;
	}

	@ResponseBody
	@RequestMapping(value = "/findAllSlist/{userId}", method = {
			RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	public String findAllSlist(@PathVariable("userId") int userId) {
		String json = playerBusiness.findAllSlist(userId);
		return json;
	}

}
